package com.fyt.ZhongYaoApp.mapper;

import com.fyt.ZhongYaoApp.pojo.Doctor;
import com.fyt.ZhongYaoApp.pojo.DoctorCat;
import com.fyt.ZhongYaoApp.pojo.vo.DoctorByCatVO;
import com.fyt.ZhongYaoApp.pojo.vo.DoctorQueery;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper

public interface DoctorMapper {

    @Insert("insert into doctor(d_name,cat_id,worktime,pat_num,star,hospital,phone,create_time,update_time)" +
            "values (#{dName},#{catId},#{worktime},#{patNum},#{star},#{hospital},#{phone},now(),now())")
    void add(Doctor doctor);


    // 查询所有
    @Select("SELECT" +
            "  `d`.`id`," +
            "  `d`.`d_name`," +
            "  `d`.`worktime`," +
            "  `d`.`pat_num`," +
            "  `d`.`star`," +
            "  `d`.`d_pic`," +
            "  `h`.`h_name`," +
            "  `d`.`phone`," +
            "  `d`.`create_time`," +
            "  `d`.`update_time`," +
            "  `c`.`dc_name`," +
            "  d.introduction, " +
            " d.drection " +
            "FROM" +
            "  `doctor` AS d" +
            "    LEFT JOIN `doctor_cat_det` AS c ON `d`.`cat_id` = `c`.`id`" +
            "    LEFT JOIN `hospital` AS h ON `d`.`hospital_id` = `h`.`id`" +
            "WHERE" +
            "  1 = 1")
    List<DoctorQueery> doctorList();

    // 根据种类查询医生信息
    @Select("SELECT" +
            "  `d`.`id`," +
            "  `d`.`d_name`," +
            "  `d`.`worktime`," +
            "  `d`.`pat_num`," +
            "  `d`.`star`," +
            "  `d`.`d_pic`," +
            "  `h`.`h_name`," +
            " d.drection, " +
            " d.level " +
            "FROM" +
            "  `doctor` AS d" +
            "    LEFT JOIN `doctor_cat_det` AS c ON `d`.`cat_id` = `c`.`id`" +
            "    LEFT JOIN `hospital` AS h ON `d`.`hospital_id` = `h`.`id`" +
            "WHERE" +
            "  c.cat_id = #{id}")
    List<DoctorByCatVO> doctorListByCat(DoctorCat doctorCat);

    /**
     * 模糊查询医生列表
     * @return
     */
    @Select("SELECT" +
            "  `d`.`id`," +
            "  `d`.`d_name`," +
            "  `d`.`worktime`," +
            "  `d`.`pat_num`," +
            "  `d`.`star`," +
            "  `d`.`d_pic`," +
            "  `h`.`h_name`," +
            " d.drection, " +
            " d.level, " +
            " d.sex " +
            "FROM" +
            "  `doctor` AS d" +
            "    LEFT JOIN `doctor_cat_det` AS c ON `d`.`cat_id` = `c`.`id`" +
            "    LEFT JOIN `hospital` AS h ON `d`.`hospital_id` = `h`.`id`" +
            "WHERE" +
//            "  d.d_name LIKE '%${name}%'")
            " h.id = #{hospitalId}")
    List<DoctorByCatVO> doctorListByName(int hospitalId);

    // 查看详情
    @Select("SELECT" +
            "  `d`.`id`," +
            "  `d`.`d_name`," +
            "  `d`.`worktime`," +
            "  `d`.`pat_num`," +
            "  `d`.`star`," +
            "  `d`.`d_pic`," +
            "  `h`.`h_name`," +
            "  `d`.`phone`," +
            "  `d`.`create_time`," +
            "  `d`.`update_time`," +
            "  `c`.`dc_name`," +
            "  d.introduction, " +
            " d.drection, " +
            " d.level " +
            "FROM" +
            "  `doctor` AS d" +
            "    LEFT JOIN `doctor_cat` AS c ON `d`.`cat_id` = `c`.`id`" +
            "    LEFT JOIN `hospital` AS h ON `d`.`hospital_id` = `h`.`id`" +
            "WHERE" +
            "  d.id = #{id}")
    List<DoctorQueery> doctorIntroduction(Doctor doctor);
}
